class Mitt {
  constructor(all) {
    this.all = all || new Map();
  }
  on(eventType, handler) {
    if (typeof eventType !== 'string' || typeof handler !== 'function') return;
    const handlers = this.all.get(eventType);
    handlers ? handlers.add(handler) : this.all.set(eventType, new Set([handler]));
  }
  off(eventType, handler) {
    if (typeof eventType !== 'string' || typeof handler !== 'function') return;
    const handlers = this.all.get(eventType);
    handlers.delete(handler);
  }
  emit(eventType, params) {
    if (typeof eventType !== 'string') return;
    const handlers = this.all.get(eventType);
    for (let handler of handlers) {
      handler(params);
    }
  }
}

const mitter = new Mitt();

const foo = a => {
  console.log('foo', a);
  return 'foo';
};

mitter.on('testone', foo);
console.log(mitter.all);

mitter.emit('testone', 100);

mitter.off('testone', foo);
console.log(mitter.all);
